import time
import unittest
from time import sleep

from dateutil.parser import parse
from selenium import webdriver
from selenium.webdriver.common.by import By


class Auto_loginTest(unittest.TestCase):

    #启动函数，每个用例测试前，都会执行该函数
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.starttime = parse(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        print("-------------------")
        print("开始测试时间：", self.starttime)
        self.driver.get("http://172.16.55.125:50042")
        self.driver.maximize_window()
        self.driver.implicitly_wait(1)

    # 结束函数，每个用例测试结束后，都会执行该函数
    def tearDown(self):
        self.driver.quit()
        self.endtime = parse(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
        print("测试结束时间：", self.endtime)
        totaltime = (self.endtime - self.starttime).total_seconds()
        print("总时长：", totaltime, "秒")

    def test_login_yunweizhuguan(self):
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/form[1]/div[1]/input').send_keys('yunweizhuguan')
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/form[1]/div[2]/input').send_keys('123asd!@#$')
        sleep(1)
        #self.driver.find_element(By.XPATH, '//button[@type="button').click()
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/button[1]').click()
        sleep(2)


    def test_login_yewuzhuguan(self):
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/form[1]/div[1]/input').send_keys('yewuzhuguan')
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/form[1]/div[2]/input').send_keys('123asd!@#$')
        sleep(1)
        #self.driver.find_element(By.XPATH, '//button[@type="button').click()
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/button[1]').click()
        sleep(2)

    def test_login_baomizhuguan(self):
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/form[1]/div[1]/input').send_keys('baomizhuguan')
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/form[1]/div[2]/input').send_keys('123asd!@#$')
        sleep(1)
        #self.driver.find_element(By.XPATH, '//button[@type="button').click()
        self.driver.find_element(By.XPATH, '//*[@id="login-page"]/div[5]/button[1]').click()
        sleep(2)


if __name__ == "__main__":
    #unittest.main()
    Auto_loginTest()
